package com.xyy.saas.payment.merchant.core.service;

import com.xyy.saas.payment.cores.enums.OpenPayStatusEnum;
import com.xyy.saas.payment.dao.model.OpenpayInfo;
import com.xyy.saas.payment.service.impl.OpenpayInfoServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class OpenpayService {
    @Resource
    private OpenpayInfoServiceImpl openpayInfoService;

    /**
     * 查询指定账号的开通信息
     * @return
     */
    public List<OpenpayInfo> queryOpenInfoByAccount(String accountId, Long thirdUserInfoId) {
        return openpayInfoService.queryUserInfoByAccountId(accountId, thirdUserInfoId);
    }

    /**
     * 更新开通支付功能状态
     * @param status
     * @param accountId
     * @param thirdUserInfoId
     * @param powerId
     */
    public boolean updateStatusByPowerId(OpenPayStatusEnum status, String accountId, Long thirdUserInfoId, String powerId) {
        OpenpayInfo record = new OpenpayInfo();
        record.setStatus(status.getStatus());
        record.setAccountId(accountId);
        record.setThirdUserInfoId(thirdUserInfoId);
        record.setPowerId(powerId);
        return openpayInfoService.updateStatusByPowerId(record) > 0;
    }
}
